package com.rslai.commons.validator.jsonvalidator.validators;

import com.rslai.commons.validator.jsonvalidator.schema.Schema;

/**
 * JSON校验器，schema校验器
 */
public class SchemaValidator extends Validator{
    public static final String VALIDATOR_NAME = "schema";
    private String parentKey;

    /**
     * 构造函数
     * @param parentKey 父节点key
     * @param schema schema
     */
    public SchemaValidator(String parentKey , Schema<Object> schema) {
        this.parentKey = parentKey;
        setValueSchema(schema);
    }

    /**
     * 校验JSON对象
     * @param object 待验证的JSON对象
     */
    @Override
    public void doValidate(Object object) {
        ((Schema<Object>)getValueSchema()).validate(parentKey, object);
    }

    /**
     * 返回校验名称
     * @return 校验名称
     */
    @Override
    public String name() {
        return VALIDATOR_NAME;
    }
}
